package com.guojiaming.shop.bean;

import com.guojiaming.shop.exception.BuildException;

import java.util.List;

/**
 * @author vivo
 */
public class ResponseFactory {

    private ResponseFactory() {
        throw new BuildException("不能使用这个类的构造器");
    }

    public static <T> ResponseBody<T> success(T data) {
        return success(data, "加载成功");
    }

    public static <T> ResponseBody<T> success(T data, String msg) {
        return success(data, msg, 1);
    }

    public static <T> ResponseBody<T> success(T data, String msg, int code) {
        ResponseBody<T> body = new ResponseBody<>();
        body.setCode(code);
        body.setMsg(msg);
        body.setData(data);
        return body;
    }

    public static <T> ResponseBody<ListBody<T>> list(List<T> data) {
        return list(data, "加载成功");
    }

    public static <T> ResponseBody<ListBody<T>> list(List<T> data, String msg) {
        return list(data, msg, 1);
    }

    public static <T> ResponseBody<ListBody<T>> list(List<T> data, String msg, int code) {
        ResponseBody<ListBody<T>> body = new ResponseBody<>();
        body.setCode(code);
        body.setMsg(msg);
        body.setData(new ListBody<>(data));
        return body;
    }

    public static ResponseBody<String> failed() {
        return failed("加载失败");
    }

    public static ResponseBody<String> failed(String msg) {
        return failed(msg, -1);
    }

    public static ResponseBody<String> failed(String msg, int code) {
        ResponseBody<String> body = new ResponseBody<>();
        body.setCode(code);
        body.setMsg(msg);
        return body;
    }
}
